<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>修改试题</title>
	<meta name="description" content="这是一个 index 页面">
	<meta name="keywords" content="index">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="renderer" content="webkit">
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="icon" type="image/png" href="../assets/i/favicon.png">
	<link rel="apple-touch-icon-precomposed" href="../assets/i/app-icon72x72@2x.png">
	<meta name="apple-mobile-web-app-title" content="Amaze UI" />
	<link rel="stylesheet" href="../assets/css/amazeui.min.css" />
	<link rel="stylesheet" href="../assets/css/amazeui.datatables.min.css" />
	<link rel="stylesheet" href="../assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="../assets/css/app.css">
	<link rel="stylesheet" href="../assets/css/gb_my.css">
	<link rel="stylesheet" href="../assets/css/font-awesome.css">
	<link rel="stylesheet" href="../assets/css/bootstrap-reset.css">
	<link rel="stylesheet" href="../assets/css/easydropdown.css">
</head>
<body data-type="chart">
	<div class="am-g tpl-g">
		<!--头部-->
		<nav class="navbar navbar-default top-navbar">
			<div class="navbar-header">
				<a class="navbar-brand waves-effect waves-dark" href="javascript:;">
					<img src="../assets/img/logo.png" alt="">
					<strong>轻课网考试系统</strong>
				</a>
				<div id="sideNav" href="">
					<i class="mulv QK QK-mulu"></i>
				</div>
			</div>

			<ul class="nav navbar-top-links navbar-right aaa">
				<li>
					<a id="down_" class="sign-out dropdown-button waves-effect waves-dark" href="javascript:;">
						<span class="am-icon-sign-out"></span> 退出
					</a>
				</li>
				<li>
					<a class="dropdown-button waves-effect waves-dark" href="javascript:;"><b>欢迎你, <span class="userName"></span> </b></a>
				</li>
			</ul>
		</nav>
		<!--导航栏-->
		<nav class="navbar-default navbar-side">
			<div class="sidebar-collapse">
				<!--用户头像-->
				<div class="tpl-sidebar-user-panel">
					<div class="tpl-user-panel-slide-toggleable">
						<div class="tpl-user-panel-profile-picture">
							<img src="../assets/img/user04.png" alt="">
						</div>
					</div>
				</div>
				<dl class="list_dl">
					<dt class="list_dt">
					<a href="../index.html">
						<span class="QK1 start_before"></span>
						<p>首页</p>
					</a>
				</dt>
					<dt id="open" class="list_dt">
					<span class="QK1 topic_before"></span>
					<p>题库管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd" style="display: block">
						<ul>
							<li class="list_li">
								<a href="../questiondb/questiondb.html">管理题库</a>
							</li>
							<li class="list_li" id="style_li_a">
								<a href="../question/question.html">管理试题</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
					<span class="QK1 paper_before"></span>
					<p>试卷管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../paper/addpaper.html">创建试卷</a>
							</li>
							<li class="list_li">
								<a href="../paper/paper.html">管理试卷</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
					<span class="QK1 system_before"></span>
					<p>系统管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../system.html">系统管理</a>
							</li>
							<li class="list_li">
								<a href="../admin/admin.html">管理员</a>
							</li>
							<li class="list_li">
								<a href="../adminroles/adminroles.html">角色管理</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
					<span class="QK1 user_before"></span>
					<p>用户管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../user/user.html">管理用户</a>
							</li>
							<li class="list_li">
								<a href="../user/usergroup.html">用户分组</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
						<span class="QK1 user_before"></span>
						<p>知识点模块</p>
						<i class="QK1 list_dt_icon"></i>
					</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../KnowledgePoint/KnowledgeBlock.html">管理知识点</a>
							</li>
						</ul>
					</dd>
				</dl>
			</div>
		</nav>
		<!-- 内容区域 -->
		<div id="page-wrapper">
				<div class="row">
					<div class="col-lg-12">
						<section class="panel">
							<header class="panel-heading">
								<span class="label label-primary">修改试题</span>
								<button type="button" class="btn btn-success btn-sm add_clazz btn_my" id="back">
								<span class="QK1 QK-fanhui1"></span>&nbsp;&nbsp;返回
							</button>
							</header>
							<div class="panel-body">
								<form class="form-horizontal">
									<div class="form-group">
										<label for="user-email" class="col-lg-1 col-sm-1 control-label">试题类型</label>
										<div class="col-lg-7 text_test">
											<!--<input type="text" class="form-control" name="type_all" >-->
											<select class="dropdown select" name="type_all">
												<option value="1">单选</option>
												<option value="2">多选</option>
												<option value="3">判断</option>
												<option value="4">填空</option>
												<option value="5">问答</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label for="user-email" class="col-lg-1 col-sm-1 control-label">所属题库</label>
										<div id="selected_questions" class="col-lg-7 text_test">
											<select class="dropdown select" name="dbid"></select>
										</div>
									</div>
									<div class="form-group">
										<label for="user-email" class="col-lg-1 col-sm-1 control-label">试题难度</label>
										<div class="col-lg-7 text_test">
											<select class="dropdown select" name="status">
												<option value="1">很容易</option>
												<option value="2">较容易</option>
												<option value="3">一般</option>
												<option value="4">较难</option>
												<option value="5">非常难</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label for="user-email" class="col-lg-1 col-sm-1 control-label">试题状态</label>
										<div class="col-lg-7 text_test">
											<select class="dropdown select" name="qlevel">
												<option value="1">开放</option>
												<option value="-1">不开放</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label for="user-email" class="col-lg-1 col-sm-1 control-label">试题来源</label>
										<div class="col-lg-7 text_test">
											<select class="dropdown select" name="qfrom">
												<option value="1">自主命题</option>
												<option value="2">网络下载</option>
												<option value="3">图书</option>
												<option value="4">试卷</option>
												<option value="5">其他</option>
											</select>
										</div>
									</div>
									<div class="form-group">
										<label class="col-lg-1 col-sm-1 control-label">试题知识点</label>
										<div class="col-lg-7 text_test">
											<input type="text" class="form-control screen_all_input" name= "pname" placeholder="搜查一下 相关知识点">
											<ul id="ul_so"></ul>
										</div>
									</div>
									<div class="form-group">
										<label for="user-name" class="col-lg-1 col-sm-1 control-label">题干内容</label>
										<div class="col-lg-7 text_test">
											<!--<input type="text" class="form-control" id="content" name="content" placeholder="请输入题干内容">-->
											<textarea class="form-control keydesc2" id="content" name="content"></textarea>
										</div>
									</div>
									<div class="form-group type_all">
										<label class="col-lg-1 col-sm-1 control-label">答案设置</label>
										<div class="col-lg-7 text_test type_radio add_button">
											<button type="button" class="btn btn-success btn-sm add_list_button" id="radio_add">增加选项</button>
											<label class="u-radio" data-name="radio1">
												<input id="value_A" name="skey" type="radio" value="A">
												<strong CLASS="options">A</strong>
												<div class="iconic-input">
													<i class="icon icon_raido"></i>
													<input type="text" class="form-control" name="Acontent" placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_A" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
											<label class="u-radio" data-name="radio1">
												<input id="value_B" name="skey" type="radio" value="B">
													<strong CLASS="options">B</strong>
												<div class="iconic-input">
													<i class="icon icon_raido"></i>
													<input type="text" class="form-control" name="Bcontent" placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_B" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
											<label class="u-radio" data-name="radio1">
												<input id="value_C" name="skey" type="radio" value="C">
												<strong CLASS="options">C</strong>
												<div class="iconic-input">
													<i class="icon icon_raido"></i>
													<input type="text" class="form-control" name="Ccontent" placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_C" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
											<label class="u-radio" data-name="radio1">
												<input id="value_D" name="skey" type="radio" value="D">
												<strong CLASS="options">D</strong>
												<div class="iconic-input">
													<i class="icon icon_raido"></i>
													<input type="text" class="form-control" name="Dcontent" placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_D" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
										</div>
										<div class="col-lg-7 text_test type_uncheck add_button">
											<button type="button" class="btn btn-success btn-sm add_list_button" id="check_add">增加选项</button>
											<label  class="u-checkbox">
												<input id='value_A' name="skey" type="checkbox" value='A'>
												<strong CLASS="options">A</strong>
												<div class="iconic-input">
													<i class="icon"></i>
													<input type="text" class="form-control" name='Acontent2' placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_A" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
											<label  class="u-checkbox">
												<input id='value_B' name="skey" type="checkbox" value='B'>
												<strong CLASS="options">B</strong>
												<div class="iconic-input">
													<i class="icon"></i>
													<input type="text" class="form-control" name='Bcontent2' placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_B" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
											<label  class="u-checkbox">
												<input id='value_C' name="skey" type="checkbox" value='C'>
												<strong CLASS="options">C</strong>
												<div class="iconic-input">
													<i class="icon"></i>
													<input type="text" class="form-control" name='Ccontent2' placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_C" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
											<label  class="u-checkbox">
												<input id='value_D' name="skey" type="checkbox" value='D'>
												<strong CLASS="options">D</strong>
												<div class="iconic-input">
													<i class="icon"></i>
													<input type="text" class="form-control" name='Dcontent2' placeholder="请输入选项内容">
												</div>
												<div class="delete">
													<button type="button" class="btn btn-success btn-sm add_list_button" id="delete_D" onclick="$(this).parent().parent().remove()">删除</button>
												</div>
											</label>
										</div>
										<div class="col-lg-7 text_test type_short">
											<textarea class="form-control" id="short_answer" name="shortAnswer"></textarea>
										</div>
									</div>
									<div class="form-group">
										<label class="col-lg-1 col-sm-1 control-label">试题解析</label>
										<div class="col-lg-7 text_test">
											<!--<input type="text" class="form-control" id="keydesc" name="keydesc" placeholder="请输入试题解析">-->
											<textarea class="form-control keydesc1" id="keydesc" name="keydesc"></textarea>
										</div>
									</div>
									<div class="form-group">
										<div class="col-lg-1 col-sm-1">
											<button type="button" class="btn btn-block submit_button" id="btnupdate">提交</button>
										</div>
									</div>
								</form>
							</div>
						</section>
					</div>
				</div>
			</div>
	</div>
</body>
</html>
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/theme.js"></script>
<script src="../assets/js/JCheck.js"></script>
<script src="../assets/js/easydropdown.js"></script>
<script type="text/javascript" src="../assets/js/jquery.cookie.js"></script>
<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/data.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/drilldown.js"></script>
<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
<script src="../assets/js/amazeui.min.js"></script>
<script src="../assets/js/amazeui.datatables.min.js"></script>
<script src="../assets/js/dataTables.responsive.min.js"></script>
<script src="../assets/js/app.js"></script>
<script charset="utf-8" src="../assets/kindeditor/kindeditor-all.js"></script>
<script charset="utf-8" src="../assets/kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="../assets/kindeditor/lang/zh-CN.js"></script>
<!-- <script type="text/javascript">
        KindEditor.ready(function (K) {
            window.editor = K.create('#keydesc', {
                afterBlur: function () { this.sync(); }
            });
        });
    </script>
<script type="text/javascript">
        KindEditor.ready(function (K) {
            window.editor = K.create('#content', {
                afterBlur: function () { this.sync(); }
            });
        });
    </script> -->
<script type="text/javascript">
    KindEditor.ready(function (K) {
        window.editor = K.create('#short_answer', {
            afterBlur: function () { this.sync(); }
        });
    });
</script>
<script>
	$("#back").click(function() {
		window.location.href = "question.html";
	});
	//请求题库类型
	$.ajax({
		url: localApi + "/QuestionDb/all",
		type: 'get',
		async: false,
		data: {
			apikey: '1'
		},
		success: function(result) {
			if(result.msg == "success") {
				$.each(result.data, function(n, item) {
					$("select[name='dbid']").append("<option value='" + item.id + "'>" + item.dname + "</option>");
				});
			} else {
				alert("出现bug");
			}
		}
	});
	var qid = window.location.search.split("=")[1];
    //保存定时器ID
    var tid = null;

    //延迟执行函数
    function debounce(fn, wait) {
        //设定默认的延迟时间
        wait = wait || 500;
        //清除定时器
        tid && clearTimeout(tid);
        //定时器执行
        tid = setTimeout(fn, wait);
    }
    var index = -1;
    $('.screen_all_input').keyup(function(e) {
        //获取关键词
        var keyword = $(this).val();
        var arry_name = [];
        var ul_add;
        var $as;
        //AJAX请求
        debounce(function() {
            //            $.get('server/search.php',{keyword:keyword},function(res){
            //                console.log(res);
            //            })
            $.ajax({
                url: localApi + "/QuestionDbPoint/getByName",
                type: 'get',
                async: false,
                data: {
                    apikey: '1',
                    pname: keyword
                },
                success: function(result) {
                    //                    console.log(result.data);
                    $.each(result.data, function(n, item) {
                        //						console.log(item);
                        arry_name.push(item.pname);
                    });
                    $("#ul_so").empty();
                    //                    console.log(arry_name);
                    for(var a = 0; a < arry_name.length && a <= 10; a++) {
                        ul_add = '<li class="ul_lis">' + arry_name[a] + '</li>';
                        //                        console.log(ul_add);
                        $("#ul_so").append(ul_add);
                        $("#ul_so").show();
                        //                        console.log($(".screen_all_input").width());
                        $("#ul_so").width();
                    }
                }
            });
            //隐藏列表框
            $("body").click(function() {
                $(".ul_lis").css('display', 'none');
            });
            $(document).on('click', '.ul_lis', function() {
                //                console.log($(this).text());
                $(".screen_all_input").val($(this).text());
                index = -1;
            });
            $as = $(".ul_lis");
            //            console.log($as);
            var keycode = e.keyCode;
            if(keycode === 38) {
                console.log(index);
                if(index === -1) {
                    index = $as.length - 1;
                    $($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
                } else if(index === -1 || index === 0) {
                    index = $as.length - 1;
                    $($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
                } else {
                    index--;
                    $($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
                }
            } else if(keycode === 40) {
//				console.log(index);
                if(index === ($as.length - 1)) {
                    index = 0;
                    $($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
                } else {
                    index++;
                    $($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
                }
            } else if(keycode === 13) {
                $('.screen_all_input').val($($as[index]).text());
                $("#ul_so").hide();
                change_pname = $(".screen_all_input").val();
                getPage(1);
//				index = -1;
            } else {
                $($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
            }
            $(".ul_lis").mouseover(function() {
                $(this).addClass('hover_add').siblings().removeClass('hover_add');
            }).mouseout(function() {
                $(this).addClass('hover_add').siblings().removeClass('hover_add');
            });
        }, 200);
    });

    $(document).on('click', '.search', function() {
//		console.log(111);
        change_pname = $(".screen_all_input").val();
        getPage(1);
        //		console.log(change_pname);
    });
	//请求数据
	$.ajax({
		url: localApi + "/QuestionWithBLOBs/get",
		type: 'get',
		async: false,
		data: {
			apikey: '1',
			id: qid
		},
		success: function(result) {
//		    console.log(result.data);
			if(result.msg == "success") {
                if(result.data.qtype == 2){
                    $('.type_radio').hide();
                    $('.type_short').hide();
                    $('.type_uncheck').show();
                    $('.u-checkbox').jCheckbox();
                    var answer = result.data.skey,
                        array_answer = [];
//                    console.log(answer);
                    for(var y = 0;y < answer.length;y++){
                        array_answer.push(answer[y]);
					}
					if(result.data.questionOptions.length > 4){
                        var array_number = ['E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
                        for(var t = 0;t < result.data.questionOptions.length - 4;t++){
                            var list_number = array_number[t];
                            var add_aption = '';
                            add_aption = "<label  class=\"u-checkbox\">\n" +
                                "<input id='value_"+ list_number +"' name=\"skey\" type=\"checkbox\" value='"+ list_number +"'>\n" +
                                "<strong CLASS=\"options\">"+ list_number +"</strong>\n" +
                                "<div class=\"iconic-input\">\n" +
                                "<i class=\"icon\"></i>\n" +
                                "<input type=\"text\" class=\"form-control\" name='"+ list_number +"content2' placeholder=\"请输入选项内容\">\n" +
                                "</div>\n" +
                                "</label>";
                            $('.u-checkbox').jCheckbox();
                            $('.type_uncheck').append(add_aption);
                            $('.u-checkbox').jCheckbox();
                        }
                    }
//					console.log(array_answer);
					if ($.inArray("A", array_answer) >= 0){
                        $("input[type='checkbox']").get(0).checked = true;
					}
					if($.inArray("B", array_answer) >= 0){
                        $("input[type='checkbox']").get(1).checked = true;
                    }
                    if($.inArray("C", array_answer) >= 0){
                        $("input[type='checkbox']").get(2).checked = true;
                    }
                    if($.inArray("D", array_answer) >= 0){
                        $("input[type='checkbox']").get(3).checked = true;
                    }
                    if($.inArray("E", array_answer) >= 0){
                        $("input[type='checkbox']").get(4).checked = true;
                    }
                    if($.inArray("F", array_answer) >= 0){
                        $("input[type='checkbox']").get(5).checked = true;
                    }
                    if($.inArray("G", array_answer) >= 0){
                        $("input[type='checkbox']").get(6).checked = true;
                    }
                    if($.inArray("H", array_answer) >= 0){
                        $("input[type='checkbox']").get(7).checked = true;
                    }
                    if($.inArray("I", array_answer) >= 0){
                        $("input[type='checkbox']").get(8).checked = true;
                    }
                    if($.inArray("J", array_answer) >= 0){
                        $("input[type='checkbox']").get(9).checked = true;
                    }
                    if($.inArray("K", array_answer) >= 0){
                        $("input[type='checkbox']").get(10).checked = true;
                    }
                    if($.inArray("L", array_answer) >= 0){
                        $("input[type='checkbox']").get(11).checked = true;
                    }
                    $('.u-checkbox').jCheckbox();
                }else if(result.data.qtype == 1){
                    $('.type_uncheck').hide();
                    $('.type_short').hide();
                    $('.type_radio').show();
                    if(result.data.skey == "A") {
                        $("input[name='skey']").get(0).checked = true;
                    } else if(result.data.skey == "B") {
                        $("input[name='skey']").get(1).checked = true;
                    } else if(result.data.skey == "C") {
                        $("input[name='skey']").get(2).checked = true;
                    } else if(result.data.skey == "D"){
                        $("input[name='skey']").get(3).checked = true;
                    }else if(result.data.skey == "E"){
                        $("input[name='skey']").get(4).checked = true;
                    }else if(result.data.skey == "F"){
                        $("input[name='skey']").get(5).checked = true;
                    }else if(result.data.skey == "G"){
                        $("input[name='skey']").get(6).checked = true;
                    }else if(result.data.skey == "H"){
                        $("input[name='skey']").get(7).checked = true;
                    }
                    $('.u-radio').jRadio();
                    if(result.data.questionOptions.length > 4){
                        var array_number2 = ['E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
                        for(var h = 0;h < result.data.questionOptions.length - 4;h++){
                            var list_number2 = array_number2[h];
                            var add_aption2 = '';
                            add_aption2 = '<label class="u-radio" data-name="radio1">\n' +
                                '<input id="value_'+ list_number2 +'" name="skey" type="radio" value="'+ list_number2 +'">\n' +
                                '<strong CLASS="options">'+ list_number2 +'</strong>\n' +
                                '<div class="iconic-input">\n' +
                                '<i class="icon icon_raido"></i>\n' +
                                '<input type="text" class="form-control" name="'+ list_number2 +'content" placeholder="请输入选项内容">\n' +
                                '</div>\n' +
                                "<div class=\"delete\">\n" +
                                "<button type=\"button\" class=\"btn btn-success btn-sm add_list_button\" id='delete_"+ list_number2 +"' onclick=\"$(this).parent().parent().remove()\">删除</button>\n" +
                                "</div>\n" +
                                '</label>';
                            $('.type_radio').append(add_aption2);
                            $('.u-radio').jRadio();
                        }
                    }
                }else if(result.data.qtype == 5){
                    $('.type_uncheck').hide();
                    $('.type_radio').hide();
                    $('.type_short').show();
				}
				$("select[name='dbid']").find("option[value='" + result.data.dbid + "']").attr("selected", true);
				$("select[name='type_all']").find("option[value='" + result.data.qtype + "']").attr("selected", true);
				$("select[name='status']").find("option[value='" + result.data.status + "']").attr("selected", true);
				$("select[name='qfrom']").find("option[value='" + result.data.qfrom + "']").attr("selected", true);
//				console.log(result.data);
				$("textarea[name='content']").val(result.data.content);
				$("textarea[name='shortAnswer']").val(result.data.skey);
				$("textarea[name='keydesc']").val(result.data.keydesc);
				if(typeof(result.data.questionDbPoint) != 'undefined'){
                    $("input[name='pname']").val(result.data.questionDbPoint.pname);
				}
            }else {
				alert("出现bug")
			}
            if(result.data.qtype !== 5){
				//请求选项数据
                $.ajax({
                    url: localApi + "/QuestionOptions/index",
                    type: 'get',
                    data: {
                        apikey: '1',
                        qid: qid
                    },
                    success: function(result) {
                        if(result.msg == "success") {
//			    console.log(result.data);
                            $.each(result.data, function(n, item) {
                                if(item.salisa == "A") {
                                    $("input[name='Acontent2']").val(item.soption);
                                    $("input[name='Acontent']").val(item.soption);
                                } else if(item.salisa == "B") {
                                    $("input[name='Bcontent2']").val(item.soption);
                                    $("input[name='Bcontent']").val(item.soption);
                                } else if(item.salisa == "C") {
                                    $("input[name='Ccontent2']").val(item.soption);
                                    $("input[name='Ccontent']").val(item.soption);
                                } else if(item.salisa == "D"){
                                    $("input[name='Dcontent2']").val(item.soption);
                                    $("input[name='Dcontent']").val(item.soption);
                                } else if(item.salisa == "E"){
                                    $("input[name='Econtent2']").val(item.soption);
                                    $("input[name='Econtent']").val(item.soption);
                                } else if(item.salisa == "F"){
                                    $("input[name='Fcontent2']").val(item.soption);
                                    $("input[name='Fcontent']").val(item.soption);
                                } else if(item.salisa == "G"){
                                    $("input[name='Gcontent2']").val(item.soption);
                                    $("input[name='Gcontent']").val(item.soption);
                                } else if(item.salisa == "H"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                    $("input[name='Hcontent']").val(item.soption);
                                }else if(item.salisa == "I"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                }else if(item.salisa == "J"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                }else if(item.salisa == "K"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                }else if(item.salisa == "L"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                }else if(item.salisa == "M"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                }else if(item.salisa == "N"){
                                    $("input[name='Hcontent2']").val(item.soption);
                                }
                            })
                        } else {
                            alert("出现bug")
                        }

                    }
                });
            }
		}
	});
	//修改问题
	$(document).ready(function(){
        $('.u-checkbox').jCheckbox();
        var tm_options = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
        var select_type;
        select_type = $("select[name='type_all']").parent().next();
        console.log(select_type);
        select_type.on('DOMNodeInserted', function(e) {
//            console.log($(e.target).html());
            if($(e.target).html() == '多选'){
                $('.type_radio').hide();
                $('.type_short').hide();
                $('.type_uncheck').show();
                $('.u-checkbox').jCheckbox();
                $('#check_add').click(function () {
//                    console.log(3333);
                    var number = $('#check_add').siblings();
                    console.log(number);
                    var array_item = [];
                    $.each(number , function (n ,item) {
//						console.log(item.firstElementChild.value);
                        array_item.push(item.firstElementChild.defaultValue);
                    });
//                    console.log(array_item);
                    for(var y=0; y<tm_options.length; y++){
                        var this_value2 = tm_options[y];
                        //不存在就添加!document.getElementById("value_" + this_value2)
                        if($.inArray(this_value2, array_item) < 0){
//                            console.log(this_value2);
                            $('.u-checkbox').jCheckbox();
                            var html_check = '';
                            html_check += "<label  class=\"u-checkbox\">\n" +
                                "<input id='value_"+ this_value2 +"' name=\"skey\" type=\"checkbox\" value='"+ this_value2 +"'>\n" +
                                "<strong CLASS=\"options\">"+ this_value2 +"</strong>\n" +
                                "<div class=\"iconic-input\">\n" +
                                "<i class=\"icon\"></i>\n" +
                                "<input type=\"text\" class=\"form-control\" name='"+ this_value2 +"content2' placeholder=\"请输入选项内容\">\n" +
                                "</div>\n" +
                                "<div class=\"delete\">\n" +
                                "<button type=\"button\" class=\"btn btn-success btn-sm add_list_button\" id='delete_"+ this_value2 +"' onclick=\"$(this).parent().parent().remove()\">删除</button>\n" +
                                "</div>\n" +
                                "</label>";
                            $(".type_uncheck").append(html_check);
                            $('.u-checkbox').jCheckbox();
                            return false;
                        }
                    }
                });
                $("#btnupdate").click(function() {
                    if($(e.target).html() == '多选'){
                        var numbers = $('#check_add').siblings();
                        var array_item_options = [],
                            array_answer = [];
                        $.each(numbers , function (n ,item) {
//						console.log(item.firstElementChild.value);
                            array_item_options.push(item.firstElementChild.defaultValue);
                            if($(this).hasClass('z-checked')){
                                array_answer.push($(this).find('input[name="skey"]').val());
                            }
                        });
                        var skey_split = array_answer.join('');
//                    console.log(array_item_options);
                        var soptions = [];
                        for(var i = 0 ;i < array_item_options.length;i++){
                            console.log($("input[name='"+ array_item_options[i] +"content2']"));
                            soptions.push(array_item_options[i] +$("input[name='"+ array_item_options[i] +"content2']").val());
                        }
//                        console.log(soptions);
                        $.ajax({
                            url: localApi + "/QuestionWithBLOBs/update",
                            type: 'POST',
                            data: {
                                id: qid,
                                apikey: '1',
                                qtype: $("select[name='qtype']").val(),
                                dbid: $("select[name='dbid']").val(),
                                qlevel: $("select[name='qlevel']").val(),
                                status: $("select[name='status']").val(),
                                qfrom: $("select[name='qfrom']").val(),
                                content: $("textarea[name='content']").val(),
                                pname: $("input[name=pname]").val(),
                                skey: skey_split,
                                keydesc: $("textarea[name='keydesc']").val(),
                                soption: soptions
                            },
                            success: function(result) {
                                if(result.msg == "success") {
                                    alert("修改成功");
                                    window.location.href = "question.html";
                                }else {
                                    alert("error");
                                }

                            }
                        });
                    }
                });
            }else if($(e.target).html() == '单选'){
                $('.type_uncheck').hide();
                $('.type_short').hide();
                $('.type_radio').show();
                $(".icon_raido").on('click', function () {
                    var _this = $(this),
                        block = _this.parent().parent(),
                        block_siblings = block.siblings('label');
                    block.find('input[type=radio]').attr('checked', true);
                    block.addClass('z-checked');
                    block_siblings.removeClass('z-checked');
                    block_siblings.find('input[type=radio]').attr('checked', false);
                });
                $('#radio_add').click(function (event) {
                    var number2 = $('#radio_add').siblings();
//                    console.log(number2);
                    var array_item2 = [];
                    $.each(number2 , function (n ,item) {
//						console.log(item.firstElementChild.value);
                        array_item2.push(item.firstElementChild.defaultValue);
                    });
//                    console.log(array_item2);
                    for(var i=0; i<tm_options.length; i++){
                        var this_value = tm_options[i];
                        if($.inArray(this_value, array_item2) < 0){
                            var html_radio = '';
                            html_radio += '<label class="u-radio" data-name="radio1">\n' +
                                '<input id="value_'+ this_value +'" name="skey" type="radio" value="'+ this_value +'">\n' +
                                '<strong CLASS="options">'+ this_value +'</strong>\n' +
                                '<div class="iconic-input">\n' +
                                '<i class="icon icon_raido"></i>\n' +
                                '<input type="text" class="form-control" name="'+ this_value +'content" placeholder="请输入选项内容">\n' +
                                '</div><div class="delete">\n' +
                                '<button type="button" class="btn btn-sm add_list_button" id="delete_'+ this_value +'" onclick="$(this).parent().parent().remove()">删除</button>\n' +
                                '</div>\n' +
                                '</label>';
                            $(".type_radio").append(html_radio);
                            $(".icon_raido").on('click', function () {
                                var _this = $(this),
                                    block = _this.parent().parent(),
                                    block_siblings = block.siblings('label');
                                block.find('input[type=radio]').attr('checked', true);
                                block.addClass('z-checked');
                                block_siblings.removeClass('z-checked');
                                block_siblings.find('input[type=radio]').attr('checked', false);
                            });
//                            $('.u-radio').jRadio();
//                            var tar = event.target;
//                            console.log($(tar).siblings());
//                            $(tar).siblings();

                            return false;
                        }
                    }
                });
                $("#btnupdate").click(function() {
                    if($(e.target).html() == '单选'){
                        var numbers = $('#radio_add').siblings();
                        var array_item_options = [],
                            skey_split =[];
//                        console.log(numbers);
                        $.each(numbers , function (n ,item) {
//						console.log(item.firstElementChild.value);
                            array_item_options.push(item.firstElementChild.defaultValue);
                        });
                        console.log(array_item_options);
                        $($('#radio_add').siblings()).each(function(){
                            if($(this).hasClass('z-checked')){
                                skey_split.push($(this).find('input[name="skey"]').val());
                            }
                        });
//                      console.log(skey_split);
//                      console.log(array_item_options);
                        var soptions = [];
                        for(var i = 0 ;i < array_item_options.length;i++){
                            soptions.push(array_item_options[i] +$("input[name='"+ array_item_options[i] +"content']").val());
                        }
                        console.log(soptions);
                        $.ajax({
                            url: localApi + "/QuestionWithBLOBs/update",
                            type: 'POST',
                            data: {
                                id: qid,
                                apikey: '1',
                                qtype: $("select[name='qtype']").val(),
                                dbid: $("select[name='dbid']").val(),
                                qlevel: $("select[name='qlevel']").val(),
                                status: $("select[name='status']").val(),
                                qfrom: $("select[name='qfrom']").val(),
                                content: $("textarea[name='content']").val(),
                                skey: skey_split.join(''),
                                keydesc: $("textarea[name='keydesc']").val(),
                                pname: $("input[name=pname]").val(),
                                soption: soptions
                            },
                            success: function(result) {
                                if(result.msg == "success") {
                                    alert("修改成功");
                                    window.location.href = "question.html";
                                } else {
                                    alert("error");
                                }

                            }
                        });
                    }
                });
            }else if($(e.target).html() == '问答'){
                $('.type_radio').hide();
                $('.type_uncheck').hide();
                $('.type_short').show();
                $("#btnupdate").click(function() {
                    if($(e.target).html() == '问答'){
                        $.ajax({
                            url: localApi + "/QuestionWithBLOBs/update",
                            type: 'POST',
                            data: {
                                apikey: '1',
								id: qid,
                                qtype: $("select[name='qtype']").val(),
                                dbid: $("select[name='dbid']").val(),
                                qlevel: $("select[name='qlevel']").val(),
                                status: $("select[name='status']").val(),
                                qfrom: $("select[name='qfrom']").val(),
                                content: $("textarea[name='content']").val(),
                                skey: $("textarea[name='shortAnswer']").val(),
                                keydesc: $("textarea[name='keydesc']").val(),
                                pname: $("input[name=pname]").val(),
                            },
                            success: function(result) {
                                if(result.msg == "success") {
                                    alert("修改成功");
                                    window.location.href = "question.html";
                                } else {
                                    alert("error");
                                }

                            }
                        });
                    }
                });
            }
        });
        select_type.trigger("DOMNodeInserted");
        $('.u-checkbox').jCheckbox();
    })

</script>
<script>
	$(document).ready(function() {
		$(".list_dt").on("click", function() {
			$('.list_dd').stop();
			$(this).siblings("dt").removeAttr("id");
			if($(this).attr("id") == "open") {
				$(this).removeAttr("id").siblings("dd").slideUp();
			} else {
				$(this).attr("id", "open").next().slideDown().siblings("dd").slideUp();
			}
		});
	});
</script>
<script>
	$(document).ready(function() {
		$(".dropdown-button").dropdown();
		$("#sideNav").click(function() {
			if($(this).hasClass('closed')) {
				$('.navbar-side').animate({
					left: '0px'
				});
				$(this).removeClass('closed');
				$('#page-wrapper').animate({
					'margin-left': '260px'
				});
			} else {
				$(this).addClass('closed');
				$('.navbar-side').animate({
					left: '-260px'
				});
				$('#page-wrapper').animate({
					'margin-left': '0px'
				});
			}
		});
	});
	$(".dropdown-button").dropdown();
</script>
